// components/customForm/input/input.js
const defaultInput = {
    layoutType: 1,
    // 1.左右，2上下
    name: "",
    // 表单name
    value: "",
    title: "收件人",
    // 表单标题
    type: "text",
    // input类型"text":文本，"number"：数字，"idcard"：身份证，"digit"：带小数点的数字
    password: false,
    // 是否为密码
    placeholder: "请填写收件人姓名",
    placeholderClass: "",
    disabled: false,
    // 是否禁用，默认否
    maxlength: 140,
    // 字数，默认140字
    important: false
};

const defaultStyle = {
    marginTop: "0rpx",
    borderBottom: "none",
    borderRadius: "0 0 0 0",
    padding: "0 32rpx"
};

Component({
    behaviors: [ "wx://form-field" ],
    /**
   * 组件的属性列表
   */
    properties: {
        inputConfig: {
            type: Object,
            value: {},
            observer(newVal) {
                this.setData({
                    ...newVal
                });
            }
        },
        inputStyle: {
            type: Object,
            value: {},
            observer(newVal) {
                const styles = this.data.styles;
                this.setData({
                    styles: {
                        ...styles,
                        ...newVal
                    }
                });
            }
        }
    },
    externalClasses: [ "m-class" ],
    /**
   * 组件的初始数据
   */
    data: {
        ...defaultInput,
        styles: {
            ...defaultStyle
        }
    },
    /**
   * 组件的方法列表
   */
    methods: {
        inputChange(e) {
            const {value: value} = e.detail;
            this.setData({
                value: value
            });
            const myEventDetail = {
                field: this.data.name,
                value: value
            };
            this.triggerEvent("myevent", myEventDetail, {});
        }
    }
});